import path from "path";
import {defineConfig} from "vite";
import vue from "@vitejs/plugin-vue";

import Components from "unplugin-vue-components/vite";
import {ElementPlusResolver} from "unplugin-vue-components/resolvers";

const pathSrc = path.resolve(__dirname, "src");

const url: string = "http://localhost:5000";
export default defineConfig({
    resolve: {
        alias: {
            "~/": `${pathSrc}/`,
            "@/": `${pathSrc}/`,
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@use "~/styles/element/index.scss" as *;`,
            },
        },
    },
    plugins: [
        vue(),
        Components({
            // allow auto load markdown components under `./src/components/`
            extensions: ["vue", "md"],
            // allow auto import and original components used in markdown
            include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
            resolvers: [
                ElementPlusResolver({
                    importStyle: "sass",
                }),
            ],
            dts: "src/components.d.ts",
        }),
    ],
    server: {
        port: 8082,
        host: "0.0.0.0",
        proxy: {
            "/api": {
                target: url,
                ws: true,
                rewrite: path => path.replace(/^\/api/, ""),
                changeOrigin: true,
            },
        },
    },
});
